<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: $this <498944516@qq.com>
// +----------------------------------------------------------------------
namespace app\we\model;

use think\Model;

class WeRob extends Model
{

   
    /**
     * 获取机器人
     */
    public function index($data=''){
    	
       
       switch ($data['keyword']) {
          case '@':
            $reply= $this->login($data);
            break;
          case 'INFO':
            $reply= $this->info($data);
            break;
         
          
          default:
            # code...
            break;
        } 



       return $reply;
      
    }

   
   public function login($data) {

        $hasUser = db('admin_user')->where(array('mobile' => $data['before'],'aid' => $data['aid']))->find();

        if(empty($hasUser)){
            return ['message'=>'管理员不存在'];
        }

        if(md5(md5($data['back']) . config('data_auth_key'))!= $hasUser['password']){
           return ['message'=>'密码错误'];
        }

        if(1 != $hasUser['status']){
            return ['message'=>'账号被禁用'];
        }

        $res=db('WeFans')->where('openid',$data['openid'])->update(['userid'=>$hasUser['userid']]);
        if ($res)  return ['message'=>$hasUser['name'].'登录成功'];
        return ['message'=>'登录失败'];
    }

     public function info($data) {

        $fans=model('we/WeFans')->infoForFans($data['openid']);
        return ['message'=> $fans['message']];
    }

    

    
}